﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HopeHealth.Domain.Services
{
    public class ArticleService
    {
        public bool Create(Guid id,
            string category,
            string title,
            string content,
            int creator)
        {
            Entities.Article article = new Entities.Article();
            article.Id = id;
            article.Content = content;
            article.Title = title;
            article.Category = category;
            article.Creator = creator;
            article.CreatedTime = DateTime.Now;
            article.PublishedTime = DateTime.Now;
            article.IsDeleted = false;
            article.State = 1;

            using(HHDbContext dbContext = new HHDbContext())
            {
                EntityRepository<Entities.Article> rep = new EntityRepository<Entities.Article>(dbContext);
                rep.Create(article);

                if(dbContext.SaveChanges() > 0)
                {
                    return true;
                }
            }
            return false;
        }

        public List<Entities.Article> GetAll()
        {
            using (HHDbContext dbContext = new HHDbContext())
            {
                EntityRepository<Entities.Article> rep = new EntityRepository<Entities.Article>(dbContext);
                return rep.GetList(p => p.IsDeleted == false);
            }
        }
    }
}
